package sjtu.ist.warehouse4ws.action;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import sjtu.ist.warehouse4ws.model.CustProcess;
import sjtu.ist.warehouse4ws.model.Process;
import sjtu.ist.warehouse4ws.service.ProcessService;
import sjtu.ist.warehouse4ws.service.cust.CustProcessService;

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.apache.struts2.json.annotations.JSON;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

public class ShowProcessListAction extends ActionSupport {

	private ProcessService processService;
	private CustProcessService custProcessService;
	private List<Process> processList = new ArrayList<Process>();
	private String gid;
	private String vid;
	
	public void setCustProcessService(CustProcessService custProcessService) {
		this.custProcessService = custProcessService;
	}

	//获得Process列表
	public String showProcessList(){
		
		Subject currentUser = SecurityUtils.getSubject();		
		Integer company=(Integer) currentUser.getSession().getAttribute("companyId");
		
		if(!currentUser.hasRole("superadmin"))
		{
			List<CustProcess> templist=custProcessService.getCustProcessList();
			this.processList = new ArrayList<Process>();
			for(CustProcess p : templist){
				//if(privilegeService.checkPrivilege(p.getFileId(),userCompany,userType, "read")){
					processList.add(p);
				//}
			}	
		}
		else
		{
			//processList=processService.getProcessList();
			processList=processService.getProcessListByGroupAndVersion(gid,vid);
			System.out.println(processList);
		}
		
		return SUCCESS;
	}
	
	@JSON(name = "totalProcess")
	public int getTotalProcess() {
		return this.processList.size();
	}

	@JSON(name = "Process")
	public List<Process> getProcessList() {
		return this.processList;
	}
	
	// 注入ProcessService
	public void setProcessService(ProcessService processService) {
		this.processService = processService;
	}

	public String getGid() {
		return gid;
	}

	public void setGid(String gid) {
		this.gid = gid;
	}

	public String getVid() {
		return vid;
	}

	public void setVid(String vid) {
		this.vid = vid;
	}
	
	
}